﻿


Option Strict On
Option Explicit On 
Imports IP.Core.IPData
Imports IP.Core.IPUserService
Imports IP.Core.IPCommon



''' -----------------------------------------------------------------------------
''' Project	 : IPSystemAdmin
''' Class	 : Core.IPSystemAdmin.CApplicationContext
''' 
''' -----------------------------------------------------------------------------
''' <summary>
'''  Nhiệm vụ:
''' - đảm bảo các thông tin chung về môi trường làm việc, như:
''' + user hiện tại
''' + máy client hiện tại
''' + thời gian hiện tại
''' + ...
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	[csung]	2/21/2005	Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class CApplicationContext
    Implements IControlerControl




#Region "MEMGBERS"
    Private Shared m_frm_main_form As Form
    Private Shared m_strDatabaseSchema As String
    Private Shared m_strFontName As String
    Private Shared m_strDevelopDataSource As String
    Private Shared m_strProductDatasource As String
    Private Shared m_strRunMode As String
    Private Shared m_str_current_login_name As String
    Private Shared m_strDataSource As String
    'save password y/n
    Private Shared m_strSavePasswordYN As String
    Private Shared m_strLastUsername As String
    Private Shared m_dsDecentralization As New DS_HT_PHAN_QUYEN_DETAIL
#End Region

#Region "PUBLIC"
    Public Shared Sub LoadDecentralizationByUserLogin()
        Dim v_us As New US_HT_PHAN_QUYEN_DETAIL
        m_dsDecentralization.Clear()
        Try
            v_us.open_connection()
            v_us.FillDatasetByUserLogin(m_dsDecentralization, CApplicationContext.get_curent_user())
            v_us.commit_close_connection()
        Catch ex As Exception
            v_us.rollback_close_connection()
            Throw ex
        End Try



    End Sub
    Public Function CanUseControl(ByVal ip_strFormName As String, ByVal ip_strControlName As String, ByVal ip_strControlType As String) As Boolean Implements IPCommon.IControlerControl.CanUseControl
        Return Me.CanUseThisControl(ip_strFormName, ip_strControlName, ip_strControlType)
    End Function


    Public Shared Function get_run_mode() As String
        Return m_strRunMode
    End Function
    Public Shared Function get_curent_user() As String
        Return m_str_current_login_name
    End Function

    Public Shared Function get_curent_datetime() As DateTime
        Return System.DateTime.Now.Date
    End Function

    Public Shared Function get_current_business_date() As DateTime
        Return System.DateTime.Now.Date
    End Function

    Public Shared Sub register_main_form(ByVal i_frm As Form)
        m_frm_main_form = i_frm
    End Sub

    Public Shared Function get_main_form() As Form
        Return m_frm_main_form
    End Function
    Public Shared Function getDatabaseSchema() As String
        Return m_strDatabaseSchema
    End Function

    Public Shared Sub set_current_user_name(ByVal i_strCurrentUserName As String)
        m_str_current_login_name = i_strCurrentUserName
    End Sub
    Public Shared Sub set_run_mode(ByVal i_strRunMode As String)
        m_strRunMode = i_strRunMode
    End Sub

    Public Shared Sub set_application_context(ByVal i_obj_login_info As CLoginInformation_302)
        Dim v_str_current_login_name As String = "abc"
        v_str_current_login_name = i_obj_login_info.getUserName
        m_str_current_login_name = v_str_current_login_name
        m_strDatabaseSchema = i_obj_login_info.getDatabaseSchema
    End Sub
    Public Shared Sub set_developer_datasource(ByVal i_str_dev_datasource As String)
        m_strDevelopDataSource = i_str_dev_datasource
    End Sub
    Public Shared Sub set_product_datasource(ByVal i_str_product_datasource As String)
        m_strProductDatasource = i_str_product_datasource
    End Sub
    Public Shared Sub set_font_name(ByVal i_str_font_name As String)
        m_strFontName = i_str_font_name
    End Sub
    Public Shared Function get_developer_datasource() As String
        Return m_strDevelopDataSource
    End Function
    Public Shared Function get_product_datasource() As String
        Return m_strProductDatasource
    End Function
    Public Shared Function get_font_name() As String
        Return m_strFontName
    End Function
    'Tinhth Edit
    Public Shared Function get_DataSourceName() As String
        Return m_strDataSource
    End Function
    Public Shared Sub set_DataSourceName(ByVal i_str_datasource_name as String)
        m_strDataSource = i_str_datasource_name
    End Sub
#End Region

#Region "Private Methods"
    Private Shared Sub LoadDecentralization(ByVal ip_dsDecentralization As DS_HT_PHAN_QUYEN_DETAIL)
        m_dsDecentralization = ip_dsDecentralization
    End Sub

    Private Shared Function CanUseThisControl( _
                ByVal ip_strFormName As String _
                , ByVal ip_strControlName As String _
                , ByVal ip_strControlType As String) As Boolean
        If (m_dsDecentralization.HT_PHAN_QUYEN_DETAIL.Select("FORM_NAME = '" & ip_strFormName & "' AND CONTROL_NAME ='" & ip_strControlName & "'").Length > 0) Then
            Return True
        End If
        Return False
    End Function
#End Region
End Class
